package app;

import java.util.Vector;

import com.StarMicronics.StarIOSDK.R;

import android.view.*;
import android.widget.*;
import android.view.View.OnClickListener;

public class E_PrintView {
	private E_invoce e_mailView;
	private Printer printerView;
	
	private void switchChanged(int index) {
		if (index == 0) {
			layout.removeView(e_mailView.view);
			layout.addView(printerView.view);
			button1.setEnabled(false);
			button2.setEnabled(true);
			button1.setTextColor(0xFFFFFFFF);
			button2.setTextColor(0xFFA5A5A5);
			switch_iamge.setImageDrawable(view.getResources().getDrawable(R.drawable.switch1));
		} else {
			layout.removeView(printerView.view);
			layout.addView(e_mailView.view);
			button2.setEnabled(false);
			button1.setEnabled(true);
			button2.setTextColor(0xFFFFFFFF);
			button1.setTextColor(0xFFA5A5A5);
			switch_iamge.setImageDrawable(view.getResources().getDrawable(R.drawable.switch2));
		}
	}
	
	public void cancel() {
		AppDelegate.sharedInstance().layout.removeView(view);
		printerView.e_print = null;
		printerView = null;
		e_mailView = null;
	}
	
	
	public E_PrintView(Vector<Object> param) {
		loadXml();
		printerView = new Printer((String)param.elementAt(0));
		printerView.e_print = this;
		e_mailView = new E_invoce(((Long)param.elementAt(1)).longValue());
		AppDelegate.sharedInstance().layout.addView(view);
		layout.addView(printerView.view);
	}
	
	private View view;
	private Button button1;
	private Button button2;
	private ImageView switch_iamge;
	private FrameLayout layout;
	private Button back;
	private void loadXml() {
		view = AppDelegate.sharedInstance().activity.getLayoutInflater().inflate(R.layout.e_printview, null);
		button1 = (Button) view.findViewById(R.id.button1);
		button2 = (Button) view.findViewById(R.id.button2);
		switch_iamge = (ImageView) view.findViewById(R.id.switch_image);
		layout = (FrameLayout) view.findViewById(R.id.frameLayout);
		back = (Button) view.findViewById(R.id.button_back);
		
		button1.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				switchChanged(0);
			}
		});
		button2.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				switchChanged(1);
			}
		});
		back.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				cancel();
			}
		});
		view.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				cancel();
			}
		});
		
		button1.setEnabled(false);
		button2.setEnabled(true);
		button1.setTextColor(0xFFFFFFFF);
		button2.setTextColor(0xFFA5A5A5);

	}
}
